package com.etone.smartAudit.controller;

import com.etone.smartAudit.apiIntercept.Result;
import com.etone.smartAudit.error.CustomParameterizedException;
import com.etone.smartAudit.service.GisServiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author 张任豪
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(tags = "GIS工具中心", value = "GisToolServiceController")
public class GisToolServiceController {

    private GisServiceService gisServiceService;

    @ApiOperation(value = "经纬度距离计算模板下载")
    @GetMapping("/gis/distanceTemplate")
    public void distanceTemplate(HttpServletResponse response) {
        gisServiceService.distanceTemplate(response);
    }


    @ApiOperation(value = "批量测算经纬度距离(模板)")
    @PostMapping("/gis/distanceCalculate")
    public void distanceCalculate(@ApiParam("上传测算距离模板文件") @RequestPart MultipartFile file, HttpServletResponse response) {

        try {
            gisServiceService.distanceCalculate(file, response);
        } catch (Exception e) {
            log.error("解析错误", e);
            throw new CustomParameterizedException("解析错误,请导入正确的模板文件!");
        }
    }

    @ApiOperation(value = "经纬度转换模板下载")
    @GetMapping("/gis/lonLatTemplate")
    public void lonLatTemplate(HttpServletResponse response) {
        gisServiceService.lonLatTemplate(response);
    }

    @ApiOperation(value = "批量经纬度转换(模板)")
    @PostMapping("/gis/batchLonLatConvert")
    public void batchLonLat(@ApiParam("上传经纬度模板文件") @RequestPart MultipartFile file, HttpServletResponse response) {
        try {
            gisServiceService.batchLonLat(file, response);
        } catch (Exception e) {
            log.error("解析错误", e);
            throw new CustomParameterizedException("解析错误,请导入正确的模板文件!");
        }

    }

    @ApiOperation(value = "通过模板批量计算最短距离")
    @PostMapping("/gis/miniDistanceTemplate")
    public Result miniDistance(
            @ApiParam("批量计算最短距离模板文件") @RequestPart MultipartFile file,
            HttpServletResponse response) {
        return gisServiceService.miniDistanceTemplate(file,response);
    }
}
